﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Administration.Health;

namespace SPHealth.SharePoint.HealthRules.SP.Rules.Sys
{
    class InfoFarmGuid : SPRepairableHealthAnalysisRule
    {
        #region Rule Setup
        //The Summary for the rule
        public override string Summary
        {
            get { return "The Farm GUID has not been translated for all available language packs."; }
        }

        //The Explanation for the rule and what is not working
        public override string Explanation
        {
            get { return String.Format("The Farm GUID requires translation to support all installed lanaguage packs. Currently the Farm GUID is only available for locale 1033. To review the Farm GUID for all installed languages, execute the PowerShell 'Get-SPFarm | select ID'."); }
        }

        //How to fix the issue
        public override string Remedy
        {
            get { return "There is no recorded solution for this issue. Happy 1st April."; }
        }

        //The type or error to flag this rule as
        public override SPHealthCheckErrorLevel ErrorLevel
        {
            get { return SPHealthCheckErrorLevel.Information; }
        }

        //The category to store this rule under
        public override SPHealthCategory Category
        {
            get { return SPHealthCategory.Configuration; }
        }

        #endregion

        #region Methods

        public override SPHealthAnalysisRuleAutomaticExecutionParameters AutomaticExecutionParameters
        {
            get
            {
                SPHealthAnalysisRuleAutomaticExecutionParameters retval = new SPHealthAnalysisRuleAutomaticExecutionParameters();
                retval.Schedule = SPHealthCheckSchedule.Daily;
                retval.Scope = SPHealthCheckScope.Any;
                retval.ServiceType = typeof(SPTimerService);
                retval.RepairAutomatically = false;
                return retval;
            }
        }

        // this method is called whenever the rule is executed
        public override SPHealthCheckStatus Check()
        {
            //Check to see we can actually speak to the farm first
            if (!SPFarm.Joined)
            {
                throw new InvalidOperationException();
            }

            DateTime today = DateTime.Now;

            if (today.Day == 1 && today.Month == 4)
                return SPHealthCheckStatus.Failed;

            return SPHealthCheckStatus.Passed;
        }

        // this method is called whenever the rule is repaired
        public override SPHealthRepairStatus Repair()
        {
            //Set the status of the repair
            return SPHealthRepairStatus.Unnecessary;
        }
        #endregion
    }
}
